//获取应用实例
var app = getApp();
Page({
	data:{
      list:[],
      date: '2018-09-01',
     xialaHidden: true,  //下拉选择状态
     kehuHidden: true,   //隐藏选择客户的弹窗
     blankHidden:true,	//黑色遮罩
     isScroll:true,		//允许页面滚动
     stateList:[
        {name:'全部',IsSelect: true, state: '0' },
        {name:'待提交资料',IsSelect: false, state: '1' },
        {name:'待面签',IsSelect: false, state: '2' },
        {name:'待预约',IsSelect: false, state: '3' },
        {name:'待提交银行',IsSelect: false, state: '4' },
        {name:'待实地',IsSelect: false, state: '5' },
        {name:'审批中',IsSelect: false, state: '6' },
        {name:'补材料',IsSelect: false, state: '7' },
        {name:'待签约',IsSelect: false, state: '8' },
        {name:'待撤押',IsSelect: false, state: '9' },
        {name:'待抵押',IsSelect: false, state: '10' },
        {name:'待出证',IsSelect: false, state: '11' },
        {name:'已出证',IsSelect: false, state: '12' },
        {name:'待放款',IsSelect: false, state: '13' },
        {name:'已放款',IsSelect: false, state: '14' },
        {name:'已拒绝',IsSelect: false, state: '15' },
 	 ],
	},
	   onLoad:function(options){    
      var qudao_code = options.qudao_code;
      this.setData({
           qudao_code:qudao_code
      });
    wx.showLoading({
      title: '加载中',
    });
    },
  onPullDownRefresh: function(){
    this.onShow();
    setTimeout(function(){
      wx.stopPullDownRefresh();
    },1000)
  },
  onShow:function(){
     var qudao_code = this.data.qudao_code;
     console.log(qudao_code);
    this.getData(qudao_code,0);
  },
    getData:function(qudao_code,jindu_type){
    var that = this;
    var user_id = wx.getStorageSync('user_id');
    wx.request({
      url: app.globalData.base + '/Home/MyInfo/myqudaoKeHu',
      method: 'post',
      data: {'user_id':user_id,'qudao_code':qudao_code,'jindu_type':jindu_type},
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({
           list:res.data.kehuList,
           jinliList:res.data.jingliList
        });
      },
    });
  },
  	//状态显示
    stateSelect: function(e) {
    	var toggle = !this.data.xialaHidden;
    	var scroll = !this.data.isScroll;
    	var flag = 1;
    	if(flag){
    		this.setData({
	            xialaHidden: toggle,
		    	isScroll:scroll,
	        });
	        flag = 0;
    	}
    	else{
			this.setData({
	            xialaHidden: !toggle,
		    	   isScroll:!scroll,
	        });
    	}
    	if(this.data.xialaHidden){
    		this.setData({
    			blankHidden: true,
	        });
    	}
    	else{
    		this.setData({
    			blankHidden: false,
          kehuHidden: true,
	        });
    	}
    	
   }, 
    //选中某一个状态
    selectCur: function (e) {
    	var that = this;
    	var jindu_type = e.currentTarget.dataset.state;
    	var qudao_code = that.data.qudao_code;
      that.setData({
        'jindu_type':jindu_type
      })
    	that.getData(qudao_code,jindu_type);
		 //隐藏遮罩层
		 this.setData({
            xialaHidden: true,
            blankHidden: true,
        });
   },
   //选择日期
  bindDateChange: function(e) {
     console.log('picker发送选择改变，携带值为', e.detail.value)
     this.setData({
      date: e.detail.value
     });
     var that = this;
     //时间筛选发送ajax请求
     var qudao_code = that.data.qudao_code;
     var shenqing_date = e.detail.value;
     wx.request({
      url: app.globalData.base + '/Home/MyInfo/myqudaoKeHu',
      method: 'post',
      data: {'shenqing_date':shenqing_date,'qudao_code':qudao_code},
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data);
        wx.hideLoading();
        that.setData({
           list:res.data.kehuList,
           jinliList:res.data.jingliList,
           kehuHidden: true,   //隐藏选择客户的弹窗
           blankHidden:true,  //黑色遮罩
        });
      },
    });
  },
  //客户选择
  customerSelect:function(e) {
      var toggle = !this.data.kehuHidden;
      var scroll = !this.data.isScroll;
      var flag = 1;
      if(flag){
        this.setData({
              kehuHidden: toggle,
              isScroll:scroll,
          });
          flag = 0;
      }else{
      this.setData({
              kehuHidden: !toggle,
              isScroll:!scroll,
          });
      }
      if(this.data.kehuHidden){
        this.setData({
          blankHidden: true,
          });
      }else{
        this.setData({
          blankHidden: false,
          xialaHidden:true,
          });
      }  
  },
  //选择客户
  selectqdCur:function(e){
    var that = this;
    var jingliid = e.currentTarget.dataset.jingliid;
    var qudao_code = that.data.qudao_code;
    wx.request({
      url: app.globalData.base + '/Home/MyInfo/myqudaoKeHu',
      method: 'post',
      data: {'jingli_id':jingliid,'qudao_code':qudao_code},
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data);
        wx.hideLoading();
        that.setData({
           list:res.data.kehuList,
           jinliList:res.data.jingliList,
           kehuHidden: true,   //隐藏选择客户的弹窗
           blankHidden:true,  //黑色遮罩
        });
      },
    });
  },
  //关闭黑色遮罩
  closeBlank:function(e){
    this.setData({
        blankHidden: true,
        xialaHidden: true,
        kehuHidden: true,
      });
  }
})